﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharedGenomics.Core
{
    public class ObjectPropertyWrapper
    {
        public ObjectPropertyWrapper(object target, string propertyName)
        {
            target.ThrowIfNull("target");
            propertyName.ThrowIfNull("propertyName");

            //try to get the value associated with the given property name - if this fails the argument is invalid (and an exception will be thrown...)
            object val = target.GetPropertyValue(propertyName);

            this.Target = target;
            this.PropertyName = propertyName;
        }

        public override bool Equals(object obj)
        {
            ObjectPropertyWrapper comp = obj as ObjectPropertyWrapper;
            return comp != null && Object.Equals(this.Target, comp.Target) && String.Equals(this.PropertyName, comp.PropertyName);
        }

        public override int GetHashCode()
        {
            return this.Target.GetHashCode() * this.PropertyName.GetHashCode();
        }

        public object Target { get; private set; }
        public string PropertyName { get; private set; }
        public object PropertyValue
        {
            get { return this.Target.GetPropertyValue(this.PropertyName); }
        }
    }
}
